import java.util.HashMap;
import java.util.Map;

/**
    最长不重复子串
 */
public class CodeTestA {
    public static void main(String[] args){
        String s = "abcabcabc";
        System.out.println(CodeTestA.solve(s));
    }

    public static int solve(String s){
        int n = s.length();
        int ans = 0;  //定义最大不重复长度
        Map<Character,Integer> map = new HashMap<>();
        for (int j=0,i=0;j<n;j++){
            if (map.containsKey(s.charAt(j))){
                i = Math.max(map.get(s.charAt(j)),i);
            }
            ans = Math.max(ans,j-i+1);
            map.put(s.charAt(j),j+1);
        }
        return ans;
    }
}
